home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / The GIMP 2.2.8 / gimp-2.2.8-i586-setup.exe / {app} / share / gimp / 2.0 / scripts / truchet.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2005-06-30  |  5.6 KB  |  167 lines

  1. ; The GIMP -- an image manipulation program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ;
  4. ; This program is free software; you can redistribute it and/or modify
  5. ; it under the terms of the GNU General Public License as published by
  6. ; the Free Software Foundation; either version 2 of the License, or
  7. ; (at your option) any later version.
  8. ; This program is distributed in the hope that it will be useful,
  9. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. ; GNU General Public License for more details.
  12. ; You should have received a copy of the GNU General Public License
  13. ; along with this program; if not, write to the Free Software
  14. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ;
  16. ;    Truchet  - a script to create Truchet patterns 
  17. ;                 by Adrian Likins <aklikins@eos.ncsu.edu>
  18. ;                 http://www4.ncsu.edu/~aklikins/
  19. ;    version about .8 give or take
  20. ;
  21. ;  Lots of thanks to Quartic for his help.
  22. ;
  23. ;
  24. ;         The utility of this script is left as an exercise for the reader.
  25.  
  26. (define (center-ellipse img cx cy rx ry op aa feather frad)
  27.   (gimp-ellipse-select img (- cx rx) (- cy ry) (+ rx rx ) (+ ry ry ) op aa feather frad))
  28.  
  29. (define (use-tiles img drawable height width img2 drawable2 xoffset yoffset)
  30.   (gimp-edit-copy drawable2)
  31.   (let ((floating-sel (car (gimp-edit-paste drawable FALSE))))
  32.     (gimp-layer-set-offsets floating-sel xoffset yoffset)
  33.     (gimp-floating-sel-anchor floating-sel)
  34.     )
  35. )
  36.  
  37.  
  38. (define (create-tiles img drawable1 drawable2 size thickness backcolor forecolor)
  39.   (let* (
  40.      (half-thickness (/ thickness 2))
  41.      (outer-radius (+ (/ size 2) half-thickness))
  42.      (inner-radius (- (/ size 2) half-thickness))
  43.      )
  44.  
  45.     (gimp-selection-all img)
  46.     (gimp-context-set-background backcolor)
  47.     (gimp-edit-fill drawable1 BACKGROUND-FILL)
  48.  
  49.     (let* (
  50.        (tempSize (* size 3))
  51.        (temp-img (car (gimp-image-new tempSize tempSize RGB)))
  52.        (temp-draw (car (gimp-layer-new temp-img tempSize tempSize RGB-IMAGE "Jabar" 100 NORMAL-MODE)))
  53.       )
  54.       (gimp-image-undo-disable temp-img)
  55.       (gimp-image-add-layer temp-img temp-draw 0)
  56.       (gimp-context-set-background backcolor)
  57.       (gimp-edit-fill temp-draw BACKGROUND-FILL)
  58.       
  59.       
  60.       (center-ellipse temp-img size size outer-radius outer-radius CHANNEL-OP-REPLACE TRUE FALSE 0)
  61.       (center-ellipse temp-img size size inner-radius inner-radius CHANNEL-OP-SUBTRACT TRUE FALSE 0)
  62.       
  63.       (center-ellipse temp-img (* size 2) (*  size 2)  outer-radius outer-radius CHANNEL-OP-ADD TRUE FALSE 0)
  64.       (center-ellipse temp-img (* size 2) (*  size 2)  inner-radius inner-radius CHANNEL-OP-SUBTRACT TRUE FALSE 0)
  65.       (gimp-context-set-background forecolor)
  66.       (gimp-edit-fill temp-draw BACKGROUND-FILL)
  67.       
  68.       (gimp-selection-none temp-img)
  69.  
  70.       (gimp-image-resize temp-img size size (- size) (- size))
  71.       ; woo hoo it works....finally...
  72.  
  73.  
  74.       (gimp-selection-all temp-img)
  75.       (gimp-edit-copy temp-draw)
  76.       (let ((floating-sel (car (gimp-edit-paste drawable2 FALSE))))
  77.     (gimp-floating-sel-anchor floating-sel))
  78.  
  79.       
  80.       (let ((floating-sel (car (gimp-edit-paste drawable1 FALSE))))
  81.     (gimp-floating-sel-anchor floating-sel))
  82.  
  83.       (let ((drawble (car (gimp-drawable-transform-flip-simple drawable1
  84.                                    ORIENTATION-VERTICAL
  85.                                    TRUE 0 TRUE)))))
  86.     
  87.  
  88.       ;(gimp-display-new temp-img)
  89.       (gimp-image-delete temp-img)
  90.       )
  91.     )
  92. )
  93.  
  94.  
  95. (define (script-fu-truchet size thickness backcolor forecolor xtiles ytiles)
  96.   (let* (
  97.      (width (* size xtiles))
  98.      (height (* size ytiles))
  99.      (img (car (gimp-image-new width height RGB)))
  100.      (tile (car (gimp-image-new size size RGB)))
  101.      (layer-one (car (gimp-layer-new img width height
  102.                      RGB-IMAGE "Rambis" 100 NORMAL-MODE)))
  103.      (tiledraw1 (car (gimp-layer-new tile size size
  104.                      RGB-IMAGE "Johnson" 100 NORMAL-MODE)))
  105.      (tiledraw2 (car (gimp-layer-new tile size size
  106.                      RGB-IMAGE "Cooper" 100 NORMAL-MODE)))
  107.      (Xindex 0)
  108.      (Yindex 0))
  109.  
  110.     (gimp-context-push)
  111.  
  112.     (gimp-image-undo-disable img)
  113.     (gimp-image-undo-disable tile)
  114.     
  115.     (gimp-image-add-layer img layer-one 0)
  116.     (gimp-image-add-layer tile tiledraw1 0)
  117.     (gimp-image-add-layer tile tiledraw2 0)
  118.  
  119.  
  120.     ;just to look a little better
  121.     (gimp-selection-all img)
  122.     (gimp-context-set-background backcolor)
  123.     (gimp-edit-fill layer-one BACKGROUND-FILL)
  124.     (gimp-selection-none img)
  125.  
  126.     (create-tiles tile tiledraw1 tiledraw2 size thickness backcolor forecolor)
  127.     
  128.  
  129.     (while (<= Xindex xtiles)
  130.        (while (<= Yindex ytiles)
  131.           (if (= (rand 2) 0)
  132.               (use-tiles img layer-one height width tile tiledraw1 (* Xindex size) (* Yindex size))
  133.               (use-tiles img layer-one height width tile tiledraw2 (* Xindex size) (* Yindex size))
  134.               )
  135.           (set! Yindex (+ Yindex 1))
  136.           )
  137.        (set! Yindex 0)
  138.        (set! Xindex (+ Xindex 1))
  139.        )
  140.     
  141.     
  142.     (gimp-image-delete tile)
  143.     (gimp-image-undo-enable img)
  144.     (gimp-display-new img)
  145.  
  146.     (gimp-context-pop)))
  147.  
  148.  
  149. (script-fu-register "script-fu-truchet"
  150.             _"T_ruchet..."
  151.             "Create a Truchet pattern \n\nWorks best with even sized thicknesses"
  152.             "Adrian Likins <aklikins@eos.ncsu.edu>"
  153.             "Adrian Likins"
  154.             "1997"
  155.             ""
  156.             SF-ADJUSTMENT _"Block size"        '(32 2 512 1 10 1 1)
  157.             SF-ADJUSTMENT _"Thickness"         '(2 1 512 1 10 1 1)
  158.             SF-COLOR      _"Background color"  '(255 255 255)
  159.             SF-COLOR      _"Foreground color"  '(0 0 0)
  160.             SF-ADJUSTMENT _"Number of X tiles" '(5 1 512 1 10 1 1)
  161.             SF-ADJUSTMENT _"Number of Y tiles" '(5 1 512 1 10 1 1))
  162.  
  163. (script-fu-menu-register "script-fu-truchet"
  164.              _"<Toolbox>/Xtns/Script-Fu/Patterns")
  165.